package link.wangkui.threadlocal;

public class ThreadLocalDemo {

    private static final ThreadLocal<Integer> threadLocal=new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };

    public static void main(String[] args) {
        Thread[] threads = new Thread[5];
        for (int i = 0; i < 5; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                   int num = threadLocal.get();
                    num += 5;
                    System.out.println(Thread.currentThread().getName() + ":" + num);
                }
            }, "Threads_" + i);
        }
        for (int i = 0; i < 5; i++) {
            threads[i].start();
        }
    }
}
